<?php
	header('content-type:text/html;charset=utf-8');	
	$string = file_get_contents("php://input");	
	$stringQty = strlen($string);
	if ($stringQty > 8){
		$str = unpack('C8', $string);  		
		if($str[3] == 0x1f && $str[4] == 0x8b){
			$start = 2;
		}else if($str[5] == 0x1f && $str[6] == 0x8b){
			$start = 4;
		}else{
			$start = 0;
		}		

		if($start > 0){
			$compressedString = substr($string, 2); // 2表示截取从第三位开始的字符串			
			$gztext = gzdecode($compressedString);	// gzdecode解压
			$text = urldecode($gztext);				//url编码
		}else{
			$text = $string;
		}	
	}else{
		$text = $string;
	}
	
	//$text = file_get_contents("php://input");	
	
	$arr = explode('&', $text);
	$length = sizeof($arr);	
	$left;
	$right;
	for($index=0;$index<$length;$index++){
		$key = explode(':', $arr[$index]);
		$left[$index] = $key[0];
		$right[$index] = $key[1];
	}	

	$line = file_get_contents("C:\inetpub\wwwroot\memoryfile.txt");	// 读取数据

	$md5a = '';						// MD5	
	$name = '';						// 文件名
	$size = '';						// 文件大小
	$ctim = date("Y-m-d H:i:s"); 	// 获取当前时间
	$down = '';
	$dele = '删除';
	$shar = '分享';
	$type = '';						// 文件类型
	$perc = 0;						// 0表示正常显示 (百分比)	
	
	/*
	$dn['aa'] = $string;
	$dn['bb'] = $stringQty;
	$dn['cc'] = $text;
	$dn['dd'] = $right[0];
	echo json_encode($dn);	
	*/
	

	if ($right[0] == 'down'){											// filelist.htm页面	下载
		$file = $right[1];
		$perc = 2;//round(microtime(true) * 1000);
		$dele = '取消';
		$shar = '暂停';
	}
	else if ($right[0] == 'dele'){										// filelist.htm页面	删除
		$line-=1;
		file_put_contents("C:\inetpub\wwwroot\memoryfile.txt", $line); 	// 写入数据
	}
	else if ($right[0] == 'canc'){										// filelist.htm页面	取消下载
		$perc = $right[2];			
	}
	else if ($right[0] == 'oper'){										// filelist.htm页面	暂停/开始下载
		$shar = $right[2];
		$dele = '取消';
		$perc = 10;														// 百分比
		$line = file_get_contents("C:\inetpub\wwwroot\memoryfile.txt");	// 读取数据
	}
	else if ($right[0] == 'sbcf'){										// filelist.htm页面	添加文件夹
		$name = $right[1];												// 文件夹名
		$down = '';
		$type = 'folder';		
		$line+=1;
		file_put_contents("C:\inetpub\wwwroot\memoryfile.txt", $line); 	// 写入数据
	}
	else if ($right[0] == 'path'){										// filelist.htm页面	路径跳转		
		$layer= $right[1];
		file_put_contents("C:\inetpub\wwwroot\layer.txt", $layer); 		// 写入路径数据
	}
	else if ($right[0] == 'sbki'){										// filelist.htm页面	读取信息		
		$line = file_get_contents("C:\inetpub\wwwroot\memoryfile.txt");	// 读取数据
		$layer = 0;														// 文件夹路径		
		file_put_contents("C:\inetpub\wwwroot\layer.txt", $layer); 		// 写入路径数据
	}
	else if ($right[0] == 'refr'){										// filelist.htm页面	F5刷新页面		
		$line = file_get_contents("C:\inetpub\wwwroot\memoryfile.txt");	// 读取数据
		$layer = $right[1];												// 文件夹路径		
		file_put_contents("C:\inetpub\wwwroot\layer.txt", $layer); 		// 写入路径数据
	}
	else if ($right[0] == 'uplo'){										// filelist.htm页面	上传的百分比	
		$perc = $right[1];												// 百分比
		$name = $right[2];												// 文件名
		$size = $right[3];												// 文件大小
		$dele = '取消';
		$shar = '暂停';		
	}	
	else if ($right[0] == 'fini'){										// filelist.htm页面	上传完成
		$perc = $right[1];												// 百分比
		$name = $right[2];												// 文件名
		$size = $right[3];												// 文件大小
		
		$down = '下载Q';
		$dele = '删除';
		$shar = '分享';	
	}	
	else if ($right[0] == 'reup'){										// filelist.htm页面	上传失败，重新上传
		$perc = $right[1];												// 百分比
		$name = $right[2];												// 文件名
		$size = $right[3];												// 文件大小
		
		$down = '重新上传';
		$dele = '删除';
		$shar = '';	
	}	
	else if ($right[0] == 'upcf'){										// filelist.htm页面	上传文件(checkFile)
		$size = $right[6];												// 文件大小
		$md5a = $right[8];												// MD5
		$name = $right[10];												// 文件名

		$perc = 5;														// 百分比
		$dele = '取消';
		$shar = '暂停';
		
		$line+=1;
		file_put_contents("C:\inetpub\wwwroot\memoryfile.txt", $line); 	// 写入数据
	}	
	$layer = file_get_contents("C:\inetpub\wwwroot\layer.txt");		// 读取路径数据
	
	/*
	$dn['aa'] = $string;
	$dn['bb'] = $stringQty;
	$dn['cc'] = $text;
	$dn['dd'] = $right[0];
	$dn['line'] = $line;
	$dn['layer'] = $layer;
	echo json_encode($dn);
	*/
	
	$dn0['name'] = 'AAAADDDDDDDDDDDDD.txt';
	$dn0['size'] = $line;
	$dn0['ctim'] = '2023-11-10 17:30:10';
	$dn0['down'] = '下载A';
	$dn0['dele'] = $dele;
	$dn0['shar'] = $shar;
	$dn0['fida'] = 'id0';
	$dn0['type'] = 'text';
	$dn0['perc'] = $perc;
	$dn0['udst'] = '0';
	$dn0['fldt'] = '0';

	$dn1['name'] = 'sddd息';
	$dn1['size'] = '';
	$dn1['ctim'] = '2022-11-10 15:31:10';
	$dn1['down'] = '';
	$dn1['dele'] = $dele;
	$dn1['shar'] = $shar;
	$dn1['fida'] = 'id1';
	$dn1['type'] = 'folder';
	$dn1['perc'] = $perc;
	$dn1['udst'] = '0';
	$dn1['fldt'] = '1';
	
	$dn2['name'] = 'QQQQ.jpg';
	$dn2['size'] = '11';
	$dn2['ctim'] = '2024-02-10 18:00:00';
	$dn2['down'] = '下载C';
	$dn2['dele'] = $dele;
	$dn2['shar'] = $shar;
	$dn2['fida'] = 'id2';
	$dn2['type'] = 'photo';
	$dn2['perc'] = $perc;
	$dn2['udst'] = '0';
	$dn2['fldt'] = '0';
	
	$dn3['name'] = 'WWWWW.zip';
	$dn3['size'] = '13';
	$dn3['ctim'] = '2024-02-10 18:10:00';
	$dn3['down'] = '下载D';
	$dn3['dele'] = $dele;
	$dn3['shar'] = $shar;
	$dn3['fida'] = 'id3';
	$dn3['type'] = 'zip';
	$dn3['perc'] = $perc;
	$dn3['udst'] = '0';
	$dn3['fldt'] = '0';
	
	$dn4['name'] = 'ggggg.rar';
	$dn4['size'] = '14';
	$dn4['ctim'] = '2024-02-10 18:20:00';
	$dn4['down'] = '下载D';
	$dn4['dele'] = $dele;
	$dn4['shar'] = $shar;
	$dn4['fida'] = 'id4';
	$dn4['type'] = 'rar';
	$dn4['perc'] = $perc;
	$dn4['udst'] = '0';
	$dn4['fldt'] = '0';

	$dn5['name'] = $name;
	$dn5['size'] = $size;
	$dn5['ctim'] = $ctim;
	$dn5['down'] = $down;
	$dn5['dele'] = $dele;
	$dn5['shar'] = $shar;
	$dn5['fida'] = 'id4';
	$dn5['type'] = $type;
	$dn5['perc'] = $perc;
	$dn5['udst'] = '0';
	$dn5['fldt'] = '0';
	
	$path0['name'] = '';
	$pathA['name'] = 'aaaaaaa';
	$pathB['name'] = 'bbbbbbb';
	$pathC['name'] = 'CCCCCCC';
	$pathD['name'] = 'DDDDDDD';
	$pathE['name'] = 'EEEEEEE';
	
	if ($line == '1'){
		$list = array($dn0);	
	}else if($line == '2'){
		$list = array($dn0,$dn1);
	}else if($line == '3'){
		$list = array($dn0,$dn1,$dn2);
	}else if($line == '4'){
		$list = array($dn0,$dn1,$dn2,$dn3);	
	}else if($line == '5'){
		$list = array($dn0,$dn1,$dn2,$dn3,$dn4);	
	}else if($line == '6'){
		$list = array($dn0,$dn1,$dn2,$dn3,$dn4,$dn5);
	}else{
		$list = array($dn0,$dn1,$dn2,$dn3,$dn4,$dn5);
	}
	
	if($layer == '1'){
		$path = array($pathA);	
	}else if($layer == '2'){
		$path = array($pathA,$pathB);	
	}else if($layer == '3'){
		$path = array($pathA,$pathB,$pathC);	
	}else if($layer == '4'){
		$path = array($pathA,$pathB,$pathC,$pathD);	
	}else if($layer == '5'){
		$path = array($pathA,$pathB,$pathC,$pathD,$pathE);	
	}

	$result['result'] = 'ok';
	$result['dire'] = $layer;
	$result['dird'] = '0';
	$result['offs'] = '0';
	$result['qtya'] = '3';
	$result['maxa'] = '0';
	
	/*
	arr.dire;	// 当前文件夹路径 directory
	arr.dird;	// 当前文件夹路径的文件Id(文件夹当普通文件使用)
	arr.offs;	// 当前读取偏移offset
	arr.qtya;	// 当前读取数量qty
	arr.maxa;	// 当前列表数量max
	*/	

	if($layer != '0'){		// 有路径的时候
		$result['path'] = $path;	
	}
	$result['list'] = $list;	

	echo json_encode($result);
	
	
?>